//import java.util.Scanner;
//
//public class Main{
//    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        while(scanner.hasNextLine()) {
//            String str = scanner.nextLine();
//            char[] s = str.toCharArray();
//            StringBuffer ret = new StringBuffer();
//            for(int i = 0; i<str.length(); i++) {
//                if(s[i]>='0'&&s[i]<='9') {
//                    ret.append(s[i]);
//                }
//            }
//            System.out.println(ret);
//        }
//    }
//}

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
    public static int[] xx = {1,-1,0,0};
    public static int[] yy = {0,0,1,-1};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()) {
            String[] map = new String[10];
            boolean[][] st = new boolean[10][10];
            for(int i = 0; i<10; i++) {
                map[i] = scanner.nextLine();
            }
            Queue<int[]> queue = new LinkedList<>();
            queue.add(new int[] {0,1});
            st[0][1] = true;
            int count = 0;
            int flag = 0;
            while(!queue.isEmpty()) {
                int size = queue.size();
                for(int i =0 ; i<size; i++) {
                    int[] a = queue.poll();
                    int x = a[0], y = a[1];
                    if(x == 9 && y == 8) {
                        flag = 1;
                        break;
                    }
                    for(int j = 0; j<4; j++) {
                        int dx = x+xx[j];
                        int dy = y+yy[j];
                        if(dx>=0 && dx<10 && dy>=0 && dy<10 && map[dx].charAt(dy)=='.' && !st[dx][dy]) {
                            queue.add(new int[]{dx,dy});
                            st[dx][dy] = true;
                        }
                    }
                }

                if(flag == 1) break;
                count++;
            }
            System.out.println(count);
        }
    }
}
